﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QLBH.ModelInterface;
using QLBH.DataModel;
using QLBH.Model.Controller;

namespace QLBH.FeatureModel
{
    public class PhieuThuChiModel:IPhieuThuChiModel
    {
        #region properties
        private Guid maphieu;
        private String sophieu;
        private decimal tongtien;
        private DateTime ngaytao;
        private bool loaiphieu;
        private String ghichu;
        private Guid userid;
        private String username;
        private Guid malydo;
        private String tenlydo;
        #endregion        
        #region Public member
        public Guid MAPHIEU
        {
            get
            {
                return maphieu;
            }
            set
            {
                maphieu = value;
            }
        }

        public string SOPHIEU
        {
            get
            {
                return sophieu;
            }
            set
            {
                sophieu = value;
            }
        }

        public decimal TONGTIEN
        {
            get
            {
                return tongtien;
            }
            set
            {
                tongtien = value;
            }
        }

        public DateTime NGAYTAO
        {
            get
            {
                return ngaytao;
            }
            set
            {
                ngaytao = value;
            }
        }

        public bool LOAIPHIEU
        {
            get
            {
                return loaiphieu;
            }
            set
            {
                loaiphieu = value;
            }
        }

        public string GHICHU
        {
            get
            {
                return ghichu;
            }
            set
            {
                ghichu = value;
            }
        }

        public Guid USERID
        {
            get
            {
                return userid;
            }
            set
            {
                userid = value;
            }
        }

        public string USERNAME
        {
            get
            {
                return username;
            }
            set
            {
                username = value;
            }
        }

        public Guid MALYDO 
        {
            set
            {
                malydo = value;
            }
            get
            {
                return malydo;
            }
        }

        public string TENLYDO 
        {
            set
            {
                tenlydo = value;
            }
            get
            {
                return tenlydo;
            }
        }
        #endregion        
    
        public void InitFromEntity(DataModel.PHIEUTHUCHI entity)
        {
            MAPHIEU = entity.PHIEUTCID;
            SOPHIEU = entity.SOPHIEU;
            TONGTIEN = (decimal)entity.TONGTIEN;
            NGAYTAO = (DateTime)entity.NGAYTAO;
            LOAIPHIEU = (bool)entity.LOAIPHIEU;
            GHICHU = entity.GHICHU;
            USERID = (Guid)entity.NGUOITAOID;

            NHANVIEN nv=NhanVienController.GetInstance().FindBy(nvs=> nvs.NVID==USERID).FirstOrDefault();

            if (nv!=null)
            {
                USERNAME = nv.TENNV;
            }

            MALYDO = (Guid)entity.LYDOID;

            LYDO ld = LyDoController.GetInstance().FindBy(lds => lds.ID == MALYDO).FirstOrDefault();

            if (ld!=null)
            {
                TENLYDO = ld.TEN;
            }
        }

        public DataModel.PHIEUTHUCHI ToEntity()
        {
            PHIEUTHUCHI entity = new PHIEUTHUCHI();
            entity.GHICHU = GHICHU;
            entity.LOAIPHIEU = LOAIPHIEU;
            entity.LYDOID = malydo;
            entity.NGAYTAO = NGAYTAO;
            entity.NGUOITAOID = USERID;
            entity.PHIEUTCID = MAPHIEU;
            entity.SOPHIEU = SOPHIEU;
            entity.TONGTIEN = TONGTIEN;

            return entity;

        }
    }
}
